package com.lishao.soccer.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.lishao.soccer.bean.entity.TmMember;
import com.lishao.soccer.service.TmMemberService;
import com.lishao.system.security.providers.SecurityUser;
import com.lishao.system.utils.ActionUtil;
import com.opensymphony.xwork2.ActionSupport;

public class TmMemberAction extends ActionSupport {
	TmMemberService tmMemberService;
	Long teamId;
	Long tmGameId;
	Long tmScoreListId;
	Date startDate;
	Date endDate;
	
	public String selectTechScore() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();

		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		List<TmMember> techScoreList = null;
		if(tmScoreListId!=null&&tmScoreListId>0){
			techScoreList = tmMemberService.selectTechScore(tmScoreListId);
		}else{
			techScoreList = tmMemberService.selectTechScore(teamId, tmGameId, startDate, endDate);
		}
		
		Map resMap = new HashMap();
		resMap.put("techScoreList", techScoreList);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}
	
	public String selectScoreList() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();

		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		List<TmMember> scoreList = null;
		if(tmScoreListId!=null&&tmScoreListId>0){
			scoreList = tmMemberService.selectScoreList(tmScoreListId);
		}else{
			scoreList = tmMemberService.selectScoreList(teamId, tmGameId, startDate, endDate);
		}
		Map resMap = new HashMap();
		resMap.put("scoreList", scoreList);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}
	
	public String selectAssistList() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();

		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		List<TmMember> assistList = null;
		if(tmScoreListId!=null&&tmScoreListId>0){
			assistList = tmMemberService.selectAssistList(tmScoreListId);
		}else{
			assistList = tmMemberService.selectAssistList(teamId, tmGameId, startDate, endDate);
		}
		Map resMap = new HashMap();
		resMap.put("assistList", assistList);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}
	
	public String selectDisciplineList() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();

		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		List<TmMember> disciplineList = null;
		if(tmScoreListId!=null&&tmScoreListId>0){
			disciplineList = tmMemberService.selectDisciplineList(tmScoreListId);
		}else{
			disciplineList = tmMemberService.selectDisciplineList(teamId, tmGameId, startDate, endDate);
		}
		Map resMap = new HashMap();
		resMap.put("disciplineList", disciplineList);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}
	
	public String selectArriveGameProportionList() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();

		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		List<TmMember> arriveGameProportionList = null;
		if(tmScoreListId!=null&&tmScoreListId>0){
			arriveGameProportionList = tmMemberService.selectArriveGameProportionList(tmScoreListId);
		}else{
			arriveGameProportionList = tmMemberService.selectArriveGameProportionList(teamId, tmGameId, startDate, endDate);
		}
		Map resMap = new HashMap();
		resMap.put("arriveGameProportionList", arriveGameProportionList);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}
	
	public String selectByTeamUser()throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();

		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		TmMember tmMember=tmMemberService.selectByTeamUser(teamId, secUser.getSmUser());
		
		Map resMap = new HashMap();
		resMap.put("tmMember", tmMember);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}
	public String selectByTeam()throws Exception{
		List<TmMember> tmMemberList=tmMemberService.selectByTeam(teamId);
		
		Map resMap = new HashMap();
		resMap.put("tmMemberList", tmMemberList);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}
	//get set
	public TmMemberService getTmMemberService() {
		return tmMemberService;
	}

	public void setTmMemberService(TmMemberService tmMemberService) {
		this.tmMemberService = tmMemberService;
	}

	public Long getTeamId() {
		return teamId;
	}

	public void setTeamId(Long teamId) {
		this.teamId = teamId;
	}

	public Long getTmGameId() {
		return tmGameId;
	}

	public void setTmGameId(Long tmGameId) {
		this.tmGameId = tmGameId;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Long getTmScoreListId() {
		return tmScoreListId;
	}

	public void setTmScoreListId(Long tmScoreListId) {
		this.tmScoreListId = tmScoreListId;
	}
	
}
